package gui;

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JTextField;
import java.awt.Color;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

public class MemoryFrame {

	private JFrame frame;
	private JTextField memCap;
	private JTextField memTime;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					MemoryFrame window = new MemoryFrame();
					window.frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public MemoryFrame() {
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		frame = new JFrame();
		frame.setBounds(100, 100, 827, 500);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.getContentPane().setLayout(null);
		
		JPanel memoryPanel = new JPanel();
		memoryPanel.setBounds(10, 11, 791, 440);
		frame.getContentPane().add(memoryPanel);
		memoryPanel.setLayout(null);
		
		JLabel lblMemoryOrganization = new JLabel("Memory Organization:");
		lblMemoryOrganization.setFont(new Font("OCR A Extended", Font.BOLD | Font.ITALIC, 16));
		lblMemoryOrganization.setBounds(10, 11, 224, 33);
		memoryPanel.add(lblMemoryOrganization);
		
		JLabel lblMemoryCapacity = new JLabel("Memory Capacity (as 16-bit words):");
		lblMemoryCapacity.setBounds(47, 78, 203, 14);
		memoryPanel.add(lblMemoryCapacity);
		
		JLabel lblAccessTimein = new JLabel("Access time (in cycles):");
		lblAccessTimein.setBounds(47, 131, 167, 14);
		memoryPanel.add(lblAccessTimein);
		
		memCap = new JTextField();
		memCap.setBounds(286, 75, 44, 20);
		memoryPanel.add(memCap);
		memCap.setColumns(10);
		
		memTime = new JTextField();
		memTime.setBounds(196, 128, 44, 20);
		memoryPanel.add(memTime);
		memTime.setColumns(10);
		
		final JLabel memReq1 = new JLabel("required");
		memReq1.setForeground(Color.RED);
		memReq1.setVisible(false);
		memReq1.setFont(new Font("Tahoma", Font.ITALIC, 11));
		memReq1.setBounds(396, 78, 64, 14);
		memoryPanel.add(memReq1);
		
		final JLabel memReq2 = new JLabel("required");
		memReq2.setForeground(Color.RED);
		memReq2.setVisible(false);
		memReq2.setFont(new Font("Tahoma", Font.ITALIC, 11));
		memReq2.setBounds(396, 131, 64, 14);
		memoryPanel.add(memReq2);
		
		JButton btnNewButton = new JButton("Next ->");
		btnNewButton.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				boolean valid = true;
				if (memCap.getText().equals("")) {
					memReq1.setVisible(true);
					valid = false;
				} else {
					memReq1.setVisible(false);
				}
				if (memTime.equals("")) {
					memReq2.setVisible(true);
					valid = false;
				} else {
					memReq2.setVisible(false);
				}
				if (valid) {
					// go to next
				}
			}
		});
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
			}
		});
		btnNewButton.setBounds(650, 400, 89, 23);
		memoryPanel.add(btnNewButton);
		
		JButton button = new JButton("<- Back");
		button.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				// go to cache
			}
		});
		button.setBounds(30, 400, 89, 23);
		memoryPanel.add(button);
	}

}
